home *** CD-ROM | disk | FTP | other *** search
/ Freelog 125 / Freelog_MarsAvril2015_No125.iso / Musique / Quod Libet / quodlibet-3.3.0-installer.exe / bin / quodlibet / formats / mod.pyc (.txt) < prev    next >
Python Compiled Bytecode  |  2014-12-31  |  2KB  |  91 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.7)
  3.  
  4. import os
  5. import ctypes
  6. from quodlibet.util import load_library
  7. from quodlibet.formats._audio import AudioFile
  8. extensions = [
  9.     '.669',
  10.     '.amf',
  11.     '.ams',
  12.     '.dsm',
  13.     '.far',
  14.     '.it',
  15.     '.med',
  16.     '.mod',
  17.     '.mt2',
  18.     '.mtm',
  19.     '.okt',
  20.     '.s3m',
  21.     '.stm',
  22.     '.ult',
  23.     '.gdm',
  24.     '.xm']
  25.  
  26. try:
  27.     _modplug = load_library([
  28.         'libmodplug.so.1',
  29.         'libmodplug.so.0',
  30.         'libmodplug-1.dll'])[0]
  31. except OSError:
  32.     extensions = []
  33.  
  34. _modplug.ModPlug_GetName.argtypes = [
  35.     ctypes.c_void_p]
  36. _modplug.ModPlug_GetName.restype = ctypes.c_char_p
  37. _modplug.ModPlug_Load.argtypes = [
  38.     ctypes.c_void_p,
  39.     ctypes.c_int]
  40. _modplug.ModPlug_Load.restype = ctypes.c_void_p
  41. _modplug.ModPlug_GetLength.argtypes = [
  42.     ctypes.c_void_p]
  43. _modplug.ModPlug_GetLength.restype = ctypes.c_int
  44. _modplug.ModPlug_Unload.argtypes = [
  45.     ctypes.c_void_p]
  46. _modplug.ModPlug_Unload.restype = None
  47.  
  48. class ModFile(AudioFile):
  49.     format = 'MOD/XM/IT'
  50.     
  51.     def __init__(self, filename):
  52.         data = open(filename, 'rb').read()
  53.         f = _modplug.ModPlug_Load(data, len(data))
  54.         if not f:
  55.             raise IOError('%r not a valid MOD file' % filename)
  56.         self['~#length'] = _modplug.ModPlug_GetLength(f) // 1000
  57.         if not _modplug.ModPlug_GetName(f):
  58.             pass
  59.         title = os.path.basename(filename)
  60.         
  61.         try:
  62.             self['title'] = title.decode('utf-8')
  63.         except UnicodeError:
  64.             self['title'] = title.decode('iso-8859-1')
  65.  
  66.         _modplug.ModPlug_Unload(f)
  67.         self.sanitize(filename)
  68.  
  69.     
  70.     def write(self):
  71.         pass
  72.  
  73.     
  74.     def reload(self, *args):
  75.         artist = self.get('artist')
  76.         super(ModFile, self).reload(*args)
  77.         if artist is not None:
  78.             self.setdefault('artist', artist)
  79.  
  80.     
  81.     def can_change(self, k = None):
  82.         if k is None:
  83.             return [
  84.                 'artist']
  85.         return None == 'artist'
  86.  
  87.  
  88. info = ModFile
  89. types = [
  90.     ModFile]
  91.